<?php

      // stateCode :  5 用户名和密码不匹配;

      // 1. 获取前端发送的数据;
      // 2. 链接数据库并查询;
      // 3. 返回结果;

      $username = @$_GET["username"];
      $password = @$_GET["password"];
	  $callback = @$_GET["cb"];
      $cookie = @$_COOKIE["tocken"];
	  

      //echo "1231231   $cookie";

      if($username === "" || $password === ""){
            die("账号密码均不能为空");
      }

      $db_username = "root";
      $db_password = "";
      $db_host = "localhost:3306";

      $con = mysql_connect($db_host,$db_username,$db_password);

      if(!$con){
            $json_arr = array( "statu" => "error" , "stateCode" => "2" , "errorType" => "mySQL error".mysql_error());
            echo  json_encode($json_arr);
      }
      mysql_select_db("GP10",$con);

      $select_SQL = "SELECT username,password FROM userlist";
      
      $select_res = mysql_query($select_SQL,$con);

      if($select_res){

            if($cookie){
                  $password = $cookie;
            }else{
                  $password = md5($password);
            }

            while($row = mysql_fetch_array($select_res)){
                  if($row["username"] === $username && $row["password"] ===  $password){
                        $json_arr = array( "statu" => "success" , "stateCode" => "1");
						//json格式json_decode转化为数组
						//数组json_decode转化为json格式
						$arrJson = json_encode($json_arr);
						echo "$callback('$arrJson')";
						die();
                  }
            }
      }

      $json_arr = array( "statu" => "error" , "stateCode" => "5", "errorType" => "User name password mismatch");
      $arrJson = json_encode($json_arr);
		echo "$callback('$arrJson')";
		die();
?>